﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using Microsoft.VisualBasic;
using System.Web;
using System.Collections;
using System.Configuration;
using System.Globalization;
using System.IO;
using AspNetCs.Enumerations.Channel_Enum;

namespace AspNetCs.Common
{
    public class StringHelper
    {

        #region DateTime 方法


        /// <summary>
        /// 返回标准日期格式string
        /// </summary>
        public static string GetDate()
        {
            return DateTime.Now.ToString("yyyy-MM-dd");
        }

        /// <summary>
        /// 返回指定日期格式
        /// </summary>
        public static string GetDate(string datetimestr, string replacestr)
        {
            if (datetimestr == null)
            {
                return replacestr;
            }

            if (datetimestr.Equals(""))
            {
                return replacestr;
            }

            try
            {
                datetimestr = Convert.ToDateTime(datetimestr).ToString("yyyy-MM-dd").Replace("1900-01-01", replacestr);
            }
            catch
            {
                return replacestr;
            }
            return datetimestr;

        }


        /// <summary>
        /// 返回标准时间格式string
        /// </summary>
        public static string GetTime()
        {
            return DateTime.Now.ToString("HH:mm:ss");
        }

        /// <summary>
        /// 返回标准时间格式string
        /// </summary>
        public static string GetDateTime()
        {
            return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        /// <summary>
        /// 返回相对于当前时间的相对天数
        /// </summary>
        public static string GetDateTime(int relativeday)
        {
            return DateTime.Now.AddDays(relativeday).ToString("yyyy-MM-dd HH:mm:ss");
        }

        /// <summary>
        /// 返回标准时间格式string
        /// </summary>
        public static string GetDateTimeF()
        {
            return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fffffff");
        }

        /// <summary>
        /// 返回标准时间 
        /// </sumary>
        public static string GetStandardDateTime(string fDateTime, string formatStr)
        {
            DateTime s = Convert.ToDateTime(fDateTime);
            return s.ToString(formatStr);
        }

        /// <summary>
        /// 返回标准时间 yyyy-MM-dd HH:mm:ss
        /// </sumary>
        public static string GetStandardDateTime(string fDateTime)
        {
            return GetStandardDateTime(fDateTime, "yyyy-MM-dd HH:mm:ss");
        }
        /// <summary>
        /// 返回相差的秒数
        /// </summary>
        /// <param name="Time"></param>
        /// <param name="Sec"></param>
        /// <returns></returns>
        public static int StrDateDiffSeconds(string Time, int Sec)
        {
            TimeSpan ts = DateTime.Now - DateTime.Parse(Time).AddSeconds(Sec);
            if (ts.TotalSeconds > int.MaxValue)
            {
                return int.MaxValue;
            }
            else if (ts.TotalSeconds < int.MinValue)
            {
                return int.MinValue;
            }
            return (int)ts.TotalSeconds;
        }

        /// <summary>
        /// 返回相差的分钟数
        /// </summary>
        /// <param name="time"></param>
        /// <param name="minutes"></param>
        /// <returns></returns>
        public static int StrDateDiffMinutes(string time, int minutes)
        {
            if (time == "" || time == null)
                return 1;
            TimeSpan ts = DateTime.Now - DateTime.Parse(time).AddMinutes(minutes);
            if (ts.TotalMinutes > int.MaxValue)
            {
                return int.MaxValue;
            }
            else if (ts.TotalMinutes < int.MinValue)
            {
                return int.MinValue;
            }
            return (int)ts.TotalMinutes;
        }

        /// <summary>
        /// 返回相差的小时数
        /// </summary>
        /// <param name="time"></param>
        /// <param name="hours"></param>
        /// <returns></returns>
        public static int StrDateDiffHours(string time, int hours)
        {
            if (time == "" || time == null)
                return 1;
            TimeSpan ts = DateTime.Now - DateTime.Parse(time).AddHours(hours);
            if (ts.TotalHours > int.MaxValue)
            {
                return int.MaxValue;
            }
            else if (ts.TotalHours < int.MinValue)
            {
                return int.MinValue;
            }
            return (int)ts.TotalHours;
        }
        /// <summary>
        /// 判断是否是时间类型,出错返回:DateTime.Now;
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static DateTime isDatetime(Object value)
        {
            DateTime dtime = DateTime.Now;
            try
            {
                dtime = Convert.ToDateTime(value);
            }
            catch
            {
                dtime = DateTime.Now;
            }
            return dtime;
        }

        /// <summary>
        /// 是否时间格式
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool isDatetime_Bool(Object value)
        {
            bool Result = false;
            try
            {
                DateTime.Parse(value.ToString());
                Result = true;
            }
            catch
            {
                Result = false;
            }
            return Result;
        }



        #endregion

        /// <summary>
        /// 根据时间返回阴历
        /// </summary>
        /// <param name="ADataTime"></param>
        /// <returns></returns>
        public static string ChineseLunisolarDate(DateTime ADataTime)
        {
            try
            {

                ChineseLunisolarCalendar clc = new System.Globalization.ChineseLunisolarCalendar();
                int year = clc.GetYear(ADataTime);
                int month = clc.GetMonth(ADataTime);
                int day = clc.GetDayOfMonth(ADataTime);
                int leapMonth = clc.GetLeapMonth(year);
                return string.Format("{0}{1}{2}年{3}{4}月{5}{6}"
                    , "甲乙丙丁戊己庚辛壬癸"[(year - 4) % 10]
                    , "子丑寅卯辰巳午未申酉戌亥"[(year - 4) % 12]
                    , "鼠牛虎兔龙蛇马羊猴鸡狗猪"[(year - 4) % 12]
                    , month == leapMonth ? "闰" : ""
                    , "无正二三四五六七八九十冬腊"[leapMonth > 0 && leapMonth <= month ? month - 1 : month]
                    , "初十廿三"[day / 10]
                    , "十一二三四五六七八九"[day % 10]
                );
            }
            catch
            {
                return "";
            }
        }
        /// <summary>
        /// 替换回车换行符为html换行符
        /// </summary>
        public static string StrFormat(string str)
        {
            string str2;

            if (str == null)
            {
                str2 = "";
            }
            else
            {
                str = str.Replace("\r\n", "<br />");
                str = str.Replace("\n", "<br />");
                str2 = str;
            }
            return str2;
        }
        /// <summary>
        /// 获取URL参数
        /// </summary>
        /// <param name="strHref"></param>
        /// <param name="strName"></param>
        /// <returns></returns>
        public static string getParam(string strHref)
        {
            string result = "";
            try
            {
                int intPos = strHref.IndexOf("?");
                if (intPos < 1)
                {
                    return strHref;
                }
                else
                {
                    result += SplitString(strHref, "?")[0];
                    result += "?";
                }
                string strRight = strHref.Substring(intPos + 1);

                string[] arrPram = SplitString(strRight, "&");//SplitString方法：将某字符串按特定字符或字符串分割为字符串数组
                int i = 0;
                foreach (string str in arrPram)
                {
                    string[] arrPramName = SplitString(arrPram[i], "=");
                    result += arrPramName[0] + "=" + HttpContext.Current.Server.UrlEncode(arrPramName[1]) + "&";

                    if (str + "" == "") { break; }
                    i++;
                }
                result = result.Substring(0, result.Length - 1);
            }
            catch
            {
                result = strHref;

            }
            return result;
        }


        /// <summary>
        /// 分隔字符串
        /// </summary>
        /// <param name="str"></param>
        /// <param name="separator"></param>
        /// <returns></returns>
        public static string[] SplitString(string str, string separator)
        {
            string tmp = str;
            Hashtable ht = new Hashtable();
            int i = 0;
            int pos = tmp.IndexOf(separator);
            while (pos != -1)
            {
                ht.Add(i, tmp.Substring(0, pos));
                tmp = tmp.Substring(pos + separator.Length);
                pos = tmp.IndexOf(separator);
                i++;
            }
            ht.Add(i, tmp);
            string[] array = new string[ht.Count];
            for (int j = 0; j < ht.Count; j++)
                array[j] = ht[j].ToString();

            return array;
        }


        /// <summary>
        /// 获取用户IP
        /// </summary>
        /// <returns></returns>
        public static string Ip()
        {
            try
            {
                string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (null == result || result == String.Empty)
                {
                    result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }

                if (null == result || result == String.Empty)
                {
                    result = HttpContext.Current.Request.UserHostAddress;
                }
                return result;
            }
            catch
            {
                return "";
            }
            finally
            {

            }
            //TODO:2008-6-11
        }

        /// <summary>
        /// 替换SCRIPT标签
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static string FilterScript(string content)
        {

            string regexstr = @"<script.*</script>";

            return Regex.Replace(content, regexstr, string.Empty, RegexOptions.IgnoreCase);

        }

        #region 统计字符串在另一个字符串中出现的次数
        /// <summary>
        /// 统计字符串在另一个字符串中出现的次数
        /// </summary>
        /// <param name="text1"></param>
        /// <param name="text2"></param>
        /// <returns></returns>
        public static int countnum(string text1, string text2)
        {
            int total = 0;
            if (text1.Length >= 1 && text2.Length >= 1)
            {
                int loact = text1.IndexOf(text2);
                while (loact != -1)
                {
                    int loc = text1.IndexOf(text2) + text2.Length;
                    int len = text1.Length - loc;
                    if (loc != -1)
                    {
                        text1 = text1.Substring(loc, len);
                    }
                    loact = text1.IndexOf(text2);
                    total++;
                }
            }
            return total;
        }
        #endregion

        #region 删除字符串组中相同元素,并删除值为空的元素
        /// <summary>
        /// 删除字符串组中相同元素,并删除值为空的元素 
        /// </summary>
        /// <param name="strArr"></param>
        /// <returns></returns>
        public static string[] GetUnique(string[] strArr)
        {
            System.Collections.Specialized.NameValueCollection name = new System.Collections.Specialized.NameValueCollection();
            foreach (string s in strArr)
            {
                if (s != "")
                {
                    name[s] = s;
                }
            }
            return name.AllKeys;
        }
        #endregion
        /// <summary>
        /// 判断字符串是否为null 或Empty
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        public static string strNull(string values)
        {
            if (string.IsNullOrEmpty(values))
            {
                return "";

            }
            else
            {
                return values;

            }

        }

        /// <summary>
        /// 格式化字符串长度，超出部分显示省略号,区分汉字跟字母。汉字2个字节，字母数字一个字节,不加省略号
        /// </summary>
        /// <param name="str"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static string Instr(string str, int n)
        {

            ///
            ///格式化字符串长度，超出部分显示省略号,区分汉字跟字母。汉字2个字节，字母数字一个字节
            ///
            string temp = string.Empty;
            if (System.Text.Encoding.Default.GetByteCount(str) <= n)//如果长度比需要的长度n小,返回原字符串
            {
                return str;
            }
            else
            {
                int t = 0;
                char[] q = str.ToCharArray();
                for (int i = 0; i < q.Length && t < n; i++)
                {
                    if ((int)q[i] >= 0x4E00 && (int)q[i] <= 0x9FA5)//是否汉字
                    {
                        temp += q[i];
                        t += 2;
                    }
                    else
                    {
                        temp += q[i];
                        t++;
                    }
                }
                return temp;
            }

        }


        /// <summary>
        /// 格式化字符串长度，超出部分显示省略号,区分汉字跟字母。汉字2个字节，字母数字一个字节
        /// </summary>
        /// <param name="str"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static string stringformat(string str, int n)
        {
            ///
            ///格式化字符串长度，超出部分显示省略号,区分汉字跟字母。汉字2个字节，字母数字一个字节
            ///
            string temp = string.Empty;
            if (System.Text.Encoding.Default.GetByteCount(str) <= n)//如果长度比需要的长度n小,返回原字符串
            {
                return str;
            }
            else
            {
                int t = 0;
                char[] q = str.ToCharArray();
                for (int i = 0; i < q.Length && t < n; i++)
                {
                    if ((int)q[i] >= 0x4E00 && (int)q[i] <= 0x9FA5)//是否汉字
                    {
                        temp += q[i];
                        t += 2;
                    }
                    else
                    {
                        temp += q[i];
                        t++;
                    }
                }
                return (temp + "...");
            }
        }
        /// <summary>
        /// 判断是否转换为数字型,返回BOOL
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool isNumber_bool(string str)
        {
            try
            {
                int.Parse(str);
                return true;
            }
            catch
            {
                return false;
            }

        }

        /// <summary>
        /// 判断是否转换为数字型,返回int
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int isNumber_int(string str)
        {
            int returnValue = 0;
            try
            {

                returnValue = int.Parse(str);
            }
            catch
            {
            }
            return returnValue;
        }

        /// <summary>
        /// 判断是否转换为数字型,返回int
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int isNumber_int(object obj)
        {
            int returnValue = 0;
            try
            {
                returnValue = Convert.ToInt32(obj);
            }
            catch
            {
            }
            return returnValue;
        }



        /// <summary>
        /// 检查输入字符串是否全数字
        /// </summary>
        /// <param name="str"></param>
        /// <param name="ReturnStr"></param>
        /// <returns></returns>
        public static bool Str_IsInt(string str, out string ReturnStr)
        {
            bool ResultStr = false;
            ReturnStr = "";
            char[] strArry = str.ToCharArray();

            foreach (char charInt in strArry)
            {
                try
                {
                    if (isNumber_bool(charInt.ToString()))
                    {
                        ReturnStr += isNumber_int(charInt.ToString());
                        ResultStr = true;
                    }
                    else
                    {
                        ReturnStr = str;
                        ResultStr = false;
                        break;
                    }
                }
                catch
                {
                    ReturnStr = str;
                    break;
                }
            }
            return ResultStr;
        }


        /// <summary>
        /// 判断是否转换为decimal型,返回decimal
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static decimal isNumber_decimal(string str)
        {
            decimal returnValue = 0;
            try
            {

                returnValue = decimal.Parse(str);
            }
            catch
            {
            }
            return returnValue;
        }


        #region  替换HTML标签


        /// <summary>
        /// 替换HTML标签
        /// </summary>
        /// <param name="strContent"></param>
        /// <returns></returns>
        public static string HtmlEncrypt(string strContent)
        {
            strContent = FilterScript(strContent);
            strContent = strContent.Replace("&", "&amp;");
            strContent = strContent.Replace("'", "＇");
            strContent = strContent.Replace("<", "&lt;");
            strContent = strContent.Replace(">", "&gt;");
            strContent = strContent.Replace("\"", "&quot;");
            strContent = strContent.Replace("\n", "<br>");
            strContent = strContent.Replace(" ", "&nbsp;");
            return strContent;

        }


        /// <summary>
        ///将html标签替换回来
        /// </summary>
        /// <param name="strContent"></param>
        /// <returns></returns>
        public static string ReHtmlEncrypt(string strContent)
        {
            strContent = FilterScript(strContent);
            strContent = strContent.Replace("&amp;", "&");
            strContent = strContent.Replace("＇", "´");
            strContent = strContent.Replace("&lt;", "<");
            strContent = strContent.Replace("&gt;", ">");
            strContent = strContent.Replace("&quot;", "\"");
            strContent = strContent.Replace("<br>", "\n");
            strContent = strContent.Replace("&nbsp;", " ");
            return strContent;

        }


        /// <summary>
        ///将html标签替换为空,专用于文件上传
        /// </summary>
        /// <param name="strContent"></param>
        /// <returns></returns>
        public static string ReHtmlEncrypt_UP(string strContent)
        {
            strContent = FilterScript(strContent);
            strContent = strContent.Replace("&amp;", "");
            strContent = strContent.Replace("'", "");
            strContent = strContent.Replace("&lt;", "");
            strContent = strContent.Replace("&gt;", "");
            strContent = strContent.Replace("&quot;", "");
            strContent = strContent.Replace("<br>", "");
            strContent = strContent.Replace("&nbsp;", "");
            strContent = strContent.Replace(";", "");
            if (strContent == "")
            {
                strContent = StringHelper.Ip().Replace(".", "").Trim() + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day;
            }
            return strContent;
        }




        /// <summary>
        /// 配制非法关键字过滤
        /// </summary>
        /// <param name="Str"></param>
        /// <returns></returns>
        public static string ConfigRepalce(string Str)
        {
            Str = FilterScript(Str);
            Str = Str.Replace("'", "＇");
            Str = Str.Replace("\"", "＂");
            Str = Str.Replace("<", "&lt;");
            Str = Str.Replace(">", "&gt;");
            Str = Str.Replace("\n", "");
            Str = Str.Replace("\r", "¤");

            return Str;
        }
        /// <summary>
        /// 将过滤的非法关键字替换回来
        /// </summary>
        /// <param name="Str"></param>
        /// <returns></returns>
        public static string ConfigRepalce_Re(string Str)
        {
            Str = Str.Replace("＇", "'");
            Str = Str.Replace("＂", "\"");
            Str = Str.Replace("&lt;", "<");
            Str = Str.Replace("&gt;", ">");
            Str = Str.Replace("¤", "\r");
            return Str;
        }






        #endregion


        /// <summary>
        /// 生成随机数
        /// </summary>
        /// <param name="Length"></param>
        /// <returns></returns>
        public static string GenerateRandom(int Length)
        {
            char[] constant ={   
                                                 '2','3','4','5','6','7','8','9',   
                                                 'a','b','c','d','e','f','g','h','i','j','k','m','n','p','q','r','s','t','u','v','w','x','y','z',   
                                                 'A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z'   
                                             };
            System.Text.StringBuilder newRandom = new System.Text.StringBuilder(56);
            Random rd = new Random();
            for (int i = 0; i < Length; i++)
            {
                newRandom.Append(constant[rd.Next(56)]);
            }
            return newRandom.ToString();
        }

        #region  过滤所有ＨＴＭＬ标记
        /// <summary>
        /// 过滤所有ＨＴＭＬ标记
        /// </summary>
        /// <param name="Htmlstring"></param>
        /// <returns></returns>
        public static string RemoveHtml(string Htmlstring) //去除HTML标记 
        {
            //删除脚本 
            Htmlstring = Regex.Replace(Htmlstring, @"(?s)<script.*?>.*?</script>", "", RegexOptions.IgnoreCase);
            //删除样式 
            Htmlstring = Regex.Replace(Htmlstring, @"(?s)<style.*?>.*?</style>", "", RegexOptions.IgnoreCase);
            //删除HTML 
            Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
            //Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);

            Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);

            Htmlstring = Htmlstring.Replace("<", "〈");
            Htmlstring = Htmlstring.Replace(">", "〉");
            // Htmlstring = Htmlstring.Replace("\r\n", "");
            Htmlstring = Htmlstring = Htmlstring.Replace(" ", "");
            Htmlstring = Htmlstring.Replace("“", "“");
            Htmlstring = Htmlstring.Replace("”", "”");
            Htmlstring = Htmlstring.Replace("&", "&");
            Htmlstring = System.Web.HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();

            return Htmlstring;
        }
        #endregion


        /// <summary>
        /// 读取WEB.Config的值
        /// </summary>
        /// <param name="Config_key">web.Config的键值</param>
        /// <returns></returns>
        public static string ReadConfig(string Config_key)
        {
            try
            {
                return ConfigurationManager.AppSettings[Config_key].ToString();
            }
            catch
            {
                return "";
            }
        }

        /// <summary>
        /// 生成随机的数字,且第一位永远不能为零
        /// </summary>
        /// <param name="VcodeNum">生成数字的个数</param>
        /// <returns>string</returns>
        public static string RndNum(int VcodeNum)
        {
            long tick = DateTime.Now.Ticks;
            Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));

            string VNum = ""; //由于字符串很短，就不用StringBuilder了

            try
            {

                #region MyRegion

                //    string Vchar = "0,1,2,3,4,5,6,7,8,9";
                //    string[] VcArray = Vchar.Split(',');
                //    int temp = -1; //记录上次随机数值，尽量避免生产几个一样的随机数

                //    //采用一个简单的算法以保证生成随机数的不同
                //    Random rand = new Random();
                //    for (int i = 1; i < VcodeNum + 1; i++)
                //    {
                //        if (temp != -1)
                //        {
                //            rand = new Random(i * temp * unchecked((int)DateTime.Now.Ticks));
                //        }
                //        int t = rand.Next(VcArray.Length);
                //        if (temp != -1 && temp == t)
                //        {
                //            return RndNum(VcodeNum);
                //        }
                //        temp = t;
                //        VNum += VcArray[t];
                //    }

                #endregion

                Random rand = new Random();
                int One = rand.Next(1, 9);

                VNum = ran.Next(10000000, 99999999).ToString();

                if (VNum.Substring(0, 1) == "0")
                {
                    VNum = One + VNum.Substring(1, VNum.Length - 1);
                }
            }
            catch
            {

            }
            return VNum;
        }



        /// <summary>
        /// 检查文件是否存在,存在就删除
        /// </summary>
        /// <param name="path">文件路径,相对于default.aspx页面</param>
        /// <returns></returns>
        public static bool delFile(string path)
        {
            string ServerPath = HttpContext.Current.Server.MapPath("~") + path;
            try
            {
                if (File.Exists(ServerPath))
                {
                    File.Delete(ServerPath);
                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch
            {
                return false;
            }
        }

        public static string FormatContent(Type dataType, string format, string Content)
        {
            string Result = Content;
            switch (dataType.ToString())
            {
                case "System.DateTime":
                    try
                    {
                        Result = StringHelper.isDatetime(Content).ToString(format);
                    }
                    catch
                    {

                    }
                    break;
                case "System.Int32":
                    Result = StringHelper.isNumber_int(Content).ToString();
                    break;
                case "System.String":
                    try
                    {
                        Result = StringHelper.stringformat(Content, StringHelper.isNumber_int(format));
                    }
                    catch
                    {
                    }
                    break;
                case "System.Decimal":

                    Result = StringHelper.isNumber_decimal(Content).ToString(format);

                    break;
                default:
                    try
                    {
                        Result = dataType.ToString();
                    }
                    catch
                    {
                    }
                    break;



            }
            return Result;

        }

        public static string FromatOnlineTime(string times)
        {
            decimal OneDay = 60 * 24;//天

            string Result = "";
            decimal CurrResult = isNumber_decimal(times);
            decimal ModValue = CurrResult % OneDay;//分钟余数
            decimal ModHour = ModValue % 60;//分钟余数
            int day = StringHelper.isNumber_int(CurrResult.ToString()) / StringHelper.isNumber_int(OneDay.ToString());//天数
            int hour = StringHelper.isNumber_int(ModValue.ToString()) / 60;//小时
            if (day > 0)
            {
                Result += day + "天";

            }
            if (hour > 0)
            {
                Result += hour + "小时";
            }
            if (ModHour > 0)
            {
                Result += ModHour + "分";
            }







            return Result;
        }

        /// <summary>
        /// 防止sql注入
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string DelSQLStr(string str)
        {
            if (str == null || str == "")
            {
                return "";
            }
            str = str.Replace(";", "");
            str = str.Replace("'", "");
            str = str.Replace("&", "");
            str = str.Replace("%20", "");
            str = str.Replace("--", "");
            str = str.Replace("==", "");
            str = str.Replace("<", "");
            str = str.Replace(">", "");
            str = str.Replace("%", "");
            str = str.Replace("+", "");
            str = str.Replace("-", "");
            str = str.Replace("=", "");
            str = str.Replace(",", "");
            return str;
        }
    }


}
